package middleware

import (
	"github.com/gin-gonic/gin"
	"nt-order/service"
	"strings"
)

func CheckListing() gin.HandlerFunc {
	return func(c *gin.Context) {
		token := strings.TrimSpace(c.Request.Header.Get("Authorization"))

		//checkToken
		if len(token) == 0 {
			panic("未传入token")
		}

		userInfo, err := new(service.UserDataPermission).GetUserPermissionByToken(token)
		if err != nil {
			panic(err)
		}

		c.Set("userInfo",*userInfo)

		c.Next()
	}
}
